package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.query.CouponQuery;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.checkerframework.checker.units.qual.A;
import org.checkerframework.checker.units.qual.Volume;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author wangyuqing
 * @since 2024-09-01
 */
@Api(tags = "优惠券相关接口")
@RestController
@RequestMapping("/coupons")
@RequiredArgsConstructor
public class CouponController {
    private final ICouponService couponService;

    /**
     * 1.新增优惠券
     *
     * @param dto 优惠券信息dto
     */
    @PostMapping
    @ApiOperation("新增优惠券")
    public void saveCoupon(@RequestBody @Valid CouponFormDTO dto) {
        couponService.saveCoupon(dto);
    }


    /**
     * 2.分页查询优惠券
     *
     * @param query 分页查询参数
     */
    @GetMapping("/page")
    @ApiOperation("分页查询优惠券")
    public PageDTO<CouponPageVO> pageQueryCoupon(CouponQuery query) {
        return couponService.pageQueryCoupon(query);
    }

    /**
     * 3.发放优惠券
     *
     * @param dto 发放优惠券的参数
     */
    @PutMapping("/{id}/issue")
    @ApiOperation("发放优惠券")
    public void beginIssue(@RequestBody @Valid CouponIssueFormDTO dto) {
        couponService.beginIssue(dto);
    }
}
